package com.my.study.handler;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
@Slf4j
/**
 * 这是bean方式
 */
public class ApplicationJobHandler {

    @XxlJob(value = "applicationJob")
    public void applicationJob() throws InterruptedException {
        // 获取页面配置参数
        String jobParam = XxlJobHelper.getJobParam();
        String[] strings = jobParam.split(",");
        String msg = strings[0];
        Integer num = Integer.parseInt(strings[1]);
        for (int i = 0; i < num; i++) {
            log.info(msg + i);
            TimeUnit.SECONDS.sleep(2);
        }
    }
}
